// const baseUrl = 'https://sxb.qcloud.com/';
const baseUrl = 'https://sharemypro.dmpp.net.cn/';
const urlR={
  baseUrl: 'https://sharemypro.dmpp.net.cn/',
  myRelease: 'Main/my_release',
  upLoad:'Upload/upload_file',
  proInfo:'Main/pro_info',
  userInfo:'users/user_info',
  qa:'users/usual_question',
  logCode:'users/user_login',
  recharge:'Pay/test_recharge',
  cash:'Pay/test_cash',
  userRes: 'users/user_res',
  editUserInfo:'users/edit_user_info',
  userCountBill:'users/user_bill',
  userCountBilldetaill:'users/detailed'
}
//wx.request
function GET(loading, url, params, callBack) {
  var header = {
    // "content-type": "application/json"
  };
  http(loading, url, params, "GET", header, callBack);
}

function POST(loading, url, params, callBack, callBackNull) {
  var header = {
    // "content-type": "application/x-www-form-urlencoded"
  };
  
  http(loading, url, params, "POST", header, callBack, callBackNull);
}

function http(loading, url, params, method, header, callBack = function () { }, callBackNull = function () { },type=true) {

  if (loading == true) {
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    })
  }

  wx.request({
    url: baseUrl + url,
    data: params,
    method: method,
    header: header,
    success: function(res) {

      if (loading == true) {
        wx.hideToast(); //隐藏提示框  
      }
      if(type){
        var _data = res.data
        if (_data.code == 200){
          callBack(_data.data);
        }else{
          model('数据获取失败', _data.msg, false, undefined, undefined, callBackNull)
        }
      }else{
        callBack(res.data);
      }
      
    },
    fail: function(er) {
      if (loading == true) {
        wx.hideToast(); //隐藏提示框
      }
    }
  })
}
//提示框
//提示 内容  取消按钮文字,按钮的文字，按钮文字的颜色
function model(title, content, showCancel = true, confirmText='确定', confirmColor = '#000000', callBack) {
  wx.showModal({
    title: title,
    content: content,
    showCancel: showCancel,
    confirmText: confirmText,
    confirmColor: confirmColor,
    success: function(res) {
      if (res.confirm) {
        callBack(res.confirm);
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
}

function ti(title, str) {
  wx.showToast({
    title: title,
    icon: str,
    duration: 2000
  })
}

module.exports = {
  urlR: urlR,
  GET: GET,
  POST: POST,
  http: http,
  model: model,
  ti: ti
}